/**
 * Copyright 2009-2011 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.myjung.model;

import java.lang.reflect.Field;

import net.myjung.model.annotation.MdlElement;
import net.myjung.util.ListMap;

/**
 * The object for adapting among other things.
 * 
 * @author Steve M. Jung
 */
@SuppressWarnings("serial")
public class TransferObject extends BaseObject {
	@MdlElement(name = "parameters")
	private ListMap<String, Object> parameterMap = new ListMap<String, Object>();
	/**
	 * Gets a parameter whose name is :name
	 * 
	 * @param name
	 *            The parameter name
	 * @return
	 */
	public Object getParameter(String name) {
		Field field = field(name);
		if (field != null) {
			try {
				return field.get(this);
			} catch (Exception e) {
			}
		}
		return parameterMap.get(name);
	}
	/**
	 * Sets a parameter value as :value whose name is :name
	 * 
	 * @param name
	 *            The parameter name
	 * @param value
	 *            The value of the parameter
	 */
	public void setParameter(String name, Object value) {
		Field field = field(name);
		if (field != null) {
			try {
				field.set(this, value);
				return;
			} catch (Exception e) {
			}
		}
		parameterMap.put(name, value);
	}
	public ListMap<String, Object> getParameterMap() {
		return parameterMap;
	}
	@Override
	public Object get(String name) {
		return getParameter(name);
	}
	@Override
	public void set(String name, Object value) {
		setParameter(name, value);
	}
}